﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MenuForm.aspx.cs" Inherits="WebApplication.Admin.MenuForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../../scripts/boot.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" method="post" runat="server">
    <asp:ScriptManager runat="server" ID="ScriptManager1">
    </asp:ScriptManager>
    <input name="ID" class="mini-hidden" runat="server" id="ID" />
    <div style="padding-left: 11px; padding-bottom: 5px;">
        <table style="table-layout: fixed;" id="formTable" width="98%">
            <tr>
                <th style="width: 100px;">
                    父级：
                </th>
                <td>
                    <input style="width: 100%;" id="PID" name="PID" class="mini-buttonedit" onbuttonclick="onButtonEdit"
                        emptytext="请选择父级" />
                </td>
                <th style="width: 100px;">
                    可见：
                </th>
                <td>
                    <input style="width: 100%;" id="Visible" name="Visible" class="mini-checkbox" value="true" />
                </td>
            </tr>
            <tr>
                <th style="width: 100px;">
                    名称：
                </th>
                <td colspan="3">
                    <span id="Text" name="Text" required="true" width="100%" class="mini-textbox" vtype="maxLength:100"
                        emptytext="请输入名称" />
                </td>
            </tr>
            <tr>
                <th style="width: 100px;">
                    图标类名：
                </th>
                <td>
                    <span id="IconClassName" name="IconClassName" width="100%" class="mini-textbox" vtype="maxLength:50"
                        emptytext="请输入图标类名" />排序： <span id="Order" name="Order" width="50%" class="mini-textbox"
                            vtype="integer" emptytext="请输入排序数字" />
                </td>
                <th style="width: 100px;">
                    排序：
                </th>
                <td>
                    <span id="Order" name="Order" width="100%" value="0" required="true" class="mini-textbox"
                        vtype="integer" emptytext="请输入排序数字" />
                </td>
            </tr>
            <tr>
                <th style="width: 100px;">
                    Url：
                </th>
                <td colspan="3">
                    <span id="Url" name="Url" width="100%" class="mini-textbox" vtype="maxLength:500"
                        emptytext="请输入Url" />
                </td>
            </tr>
        </table>
    </div>
    <div style="text-align: center; padding: 10px; border-top: 2px solid gray; margin-top: 20px;">
        <a class="mini-button" onclick="onOk" iconcls="icon-save" style="width: 60px; margin-right: 20px;">
            确定</a> <a class="mini-button" onclick="onCancel" iconcls="icon-cancel" style="width: 60px;">
                取消</a>
    </div>
    </form>
    <script type="text/javascript">
        mini.parse();
        var form = new mini.Form("form1");

        function SaveData() {
            var o = form.getData();

            form.validate();
            if (form.isValid() == false) return;
            var json = mini.encode(o);
            form.loading();
            $.ajax({
                url: "/Handler.ashx?method=SaveMenu",
                type: 'post',
                data: { data: json },
                cache: false,
                success: function (text) {
                    form.unmask();
                    var result = mini.decode(text);
                    if (result.Success) {
                        CloseWindow("changed");
                    } else {
                        mini.alert("操作失败！<br/>" + result.Message);
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    mini.alert("操作失败！<br/>" + jqXHR.responseText);
                    form.unmask();
                }
            });
        }

        ////////////////////
        //标准方法接口定义
        function SetData(data) {
            data = mini.clone(data);
            form.setData(data);
        }

        function SetParent(parentNode) {
            var data = mini.clone(parentNode);
            mini.get("PID").setValue(parentNode.ID);
            mini.get("PID").setText(parentNode.Text);
        }

        function GetData() {
            var o = form.getData();
            return o;
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }
        function onOk(e) {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }

        function onListBoxValueChanged(e) {
            //$("#ProcessTag").val(e.sender.getValue());
        }
        function onButtonEdit(e) {
            var btnEdit = this;
            mini.open({
                url: "/admin/MenuSelect.aspx?mode=single",
                title: "选择列表",
                width: 800,
                height: 600,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.SetData({ singleMode: true });
                },
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);    //必须
                        if (data) {
                            btnEdit.setValue(data.ID);
                            btnEdit.setText(data.Text);
                        }
                    }
                }
            });
        }
    </script>
</body>
</html>
